<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <ul id='list'>
    <li>
      <span>1</span>
      <button>删除</button>
    </li>
    <li>
      <span>2</span>
      <button>删除</button>
    </li>
    <li>
      <span>3</span>
      <button>删除</button>
    </li>
    <li>
      <span>4</span>
      <button>删除</button>
    </li>
  </ul>
  <script>
    // 给每一个btn添加点击事件
    // let btns = document.querySelectorAll('button');
    // let ul = document.querySelector('#list');
    // let len = btns.length;
    // for(let i=0;i<len;i++) {
    //   btns[i].onclick = function() {
    //     ul.removeChild(this.parentNode);
    //   }
    // }
      // 事件委托
    let ul = document.querySelector('#list');
    ul.addEventListener('click',function(e){
      ul.removeChild(e.target.parentNode);
    })
  </script>
</body>

</html>